bitkeeper revision 1.1662.1.16 (42a59915qzJ0eBmm6tVyIARo8G0cXA)
authorcl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Tue, 7 Jun 2005 12:54:45 +0000 (12:54 +0000)
committercl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Tue, 7 Jun 2005 12:54:45 +0000 (12:54 +0000)
params.py, SrvDaemon.py:
  Add xenstored.
ignore:
  Add tools/xenstore/xenstored.
Signed-off-by: Mike Wray <mike.wray@hp.com>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
BitKeeper/etc/ignore
tools/python/xen/xend/server/SrvDaemon.py
tools/python/xen/xend/server/params.py

index b591ce74583db29c9ff60c308879b9e262c2f698..60dabbec246b3012a9298d36add7f431cd56fbf1 100644 (file)
@@ -130,6 +130,7 @@ tools/xcutils/xc_restore
 tools/xcutils/xc_save
 tools/xenstore/testsuite/tmp/*
 tools/xenstore/xen
+tools/xenstore/xenstored
 tools/xenstore/xenstored_test
 tools/xenstore/xs_random
 tools/xenstore/xs_stress
index 51745ca465523d8fa910f679af59f338c16d9de3..c52a8acb9d8ff7ef88e9b1caba8224d91a03dc73 100644 (file)
@@ -125,9 +125,13 @@ class Daemon:
     def cleanup_xend(self, kill=False):
         return self.cleanup_process(XEND_PID_FILE, "xend", kill)
 
+    def cleanup_xenstored(self, kill=False):
+        return self.cleanup_process(XENSTORED_PID_FILE, "xenstored", kill)
+
     def cleanup(self, kill=False):
         self.cleanup_xend(kill=kill)
-            
+        self.cleanup_xenstored(kill=kill)
+
     def status(self):
         """Returns the status of the xend daemon.
         The return value is defined by the LSB:
@@ -163,6 +167,27 @@ class Daemon:
             pidfile.close()
         return pid
 
+    def start_xenstored(self):
+        """Fork and exec xenstored, writing its pid to XENSTORED_PID_FILE.
+        """
+        def mkdirs(p):
+            try:
+                os.makedirs(p)
+            except:
+                pass
+        mkdirs(XENSTORED_RUN_DIR)
+        mkdirs(XENSTORED_LIB_DIR)
+        
+        pid = self.fork_pid(XENSTORED_PID_FILE)
+        if pid:
+            # Parent
+            log.info("Started xenstored, pid=%d", pid)
+        else:
+            # Child
+            if XEND_DAEMONIZE and (not XENSTORED_DEBUG):
+                self.daemonize()
+            os.execl("/usr/sbin/xenstored", "xenstored", "--no-fork")
+
     def daemonize(self):
         if not XEND_DAEMONIZE: return
         # Detach from TTY.
@@ -193,11 +218,15 @@ class Daemon:
         4  Insufficient privileges
         """
         xend_pid = self.cleanup_xend()
+        xenstored_pid = self.cleanup_xenstored()
 
         if self.set_user():
             return 4
         os.chdir("/")
 
+        if xenstored_pid == 0:
+            self.start_xenstored()
+
         if xend_pid > 0:
             # Trying to run an already-running service is a success.
             return 0
index 7a2f8bdb1fa08b0a12f546777de2b1c1d1a13229..e78e99e632c63ab5b650c36e5a686afbf22353bc 100644 (file)
@@ -21,9 +21,14 @@ def getenv(var, val, conv=None):
     return v
 
 # The following parameters could be placed in a configuration file.
-XEND_PID_FILE     = '/var/run/xend.pid'
-XEND_TRACE_FILE   = '/var/log/xend.trace'
-XEND_DEBUG_LOG    = '/var/log/xend-debug.log'
-XEND_USER         = 'root'
-XEND_DEBUG        = getenv("XEND_DEBUG",     0, conv=int)
-XEND_DAEMONIZE    = getenv("XEND_DAEMONIZE", not XEND_DEBUG, conv=int)
+XEND_PID_FILE      = '/var/run/xend.pid'
+XEND_TRACE_FILE    = '/var/log/xend.trace'
+XEND_DEBUG_LOG     = '/var/log/xend-debug.log'
+XEND_USER          = 'root'
+XEND_DEBUG         = getenv("XEND_DEBUG",     0, conv=int)
+XEND_DAEMONIZE     = getenv("XEND_DAEMONIZE", not XEND_DEBUG, conv=int)
+
+XENSTORED_PID_FILE = '/var/run/xenstored.pid'
+XENSTORED_RUN_DIR  = '/var/run/xenstored'
+XENSTORED_LIB_DIR  = '/var/lib/xenstored'
+XENSTORED_DEBUG    = getenv("XSDAEMON_DEBUG", 0, conv=int)